package com.raising.utils;

import com.raising.framework.spring.SpringUtils;
import com.raising.modules.sys.entity.User;
import com.raising.modules.sys.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

/**
 * 用户管理工具
 * 
 * @author gaoy
 * 
 */
public class UserUtils {

	/**
	 * 用户服务对象
	 */
	private static UserService userService = SpringUtils.getBean(UserService.class);

	/**
	 * 获取当前访问用户名
	 * @return
	 */
	public static String getLoginUserName() {
		try{
			Subject subject = SecurityUtils.getSubject();
			String userName = (String) subject.getPrincipal();
			return userName;
		}catch (Exception e){
			return null;
		}
	}

//	/**
//	 * 获取当前用户标识
//	 * @return
//	 */
//	public static String getLoginUserId() {
//		String currentUserId = (String) SecurityUtils.getSubject().getSession().getAttribute("currentUserId");
//		return currentUserId;
//	}

	/**
	 * 获取当前登录用户
	 * 
	 * @return
	 */
	public static User getLoginUser() {
		try{
			Subject subject = SecurityUtils.getSubject();
			String userName = (String) subject.getPrincipal();
			return userService.getUserByUserName(userName);
		}catch (Exception e){
			return null;
		}
	}

}
